﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RaytheonTimeWindows
{
    public class Common
    {
        public delegate void DataChangedDelegate();

        public enum DayOfWeek
        {
            Saturday = 0,
            Sunday = 1,
            Monday = 2,
            Tuesday = 3,
            Wednesday = 4,
            Thursday = 5,
            Friday = 6
        }

        public static DayOfWeek ConvertDayOfWeek(DateTime date)
        {
            switch (date.DayOfWeek)
            {
                case System.DayOfWeek.Sunday:
                    return DayOfWeek.Sunday;
                case System.DayOfWeek.Saturday:
                    return DayOfWeek.Saturday;
                case System.DayOfWeek.Monday:
                    return DayOfWeek.Monday;
                case System.DayOfWeek.Tuesday:
                    return DayOfWeek.Tuesday;
                case System.DayOfWeek.Wednesday:
                    return DayOfWeek.Wednesday;
                case System.DayOfWeek.Thursday:
                    return DayOfWeek.Thursday;
                default: // case System.DayOfWeek.Friday:
                    return DayOfWeek.Friday;
            }
        }

        static public bool IsNewWeek(DateTime date1, DateTime date2)
        {
            TimeSpan ts = date2.Subtract(date1);

            if (ts.Days < 0)
            {
                throw new Exception("Common.IsNewWeek - date1 must be greater than date2");
            }

            if (ts.Days > 6)
            {
                return true;
            }

            if (ConvertDayOfWeek(date2) - ConvertDayOfWeek(date1) <= 0)
            {
                return true;
            }

            return false;
        }

        static public void DisplaySummary(Int32 wordayId)
        {
            frmSummary form = new frmSummary(wordayId);
            form.Show();
        }

        static public DateTime SetDateTime(DateTime date, String time)
        {
            String[] timeParts = time.Split(new char[] { ':' });
            Int32 hour = Convert.ToInt32(timeParts[0]);
            Int32 minute = Convert.ToInt32(timeParts[1]);
            return new DateTime(date.Year, date.Month, date.Day, hour, minute, 0);
        }
    }
}
